package org.xm.sk.vo.tb;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.xm.sk.vo.Base;
import org.xm.sk.vo.e.ActivityStatus;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
@Table(name = "dc_activity")
@ApiModel(value = "Activity", parent = Base.class, description = "优惠活动")
public class Activity extends Base {

    /**
     * 
     */
    private static final long serialVersionUID = -8464391730469871795L;

    @ApiModelProperty(value = "活动名称")
    @Column(length = 255)
    private String name;

    @ApiModelProperty(value = "发布活动的机构")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_organ_id")
    private Organ organ;

    @ApiModelProperty(value = "发行优惠券数量")
    @Column
    private Integer count;

    @ApiModelProperty(value = "活动条件")
    @Column(length = 255)
    private String conditions;

    @ApiModelProperty(value = "活动范围")
    @Column(length = 255)
    private String scope;
    
    @ApiModelProperty(value = "适用品牌")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_activity_brand", joinColumns = {
            @JoinColumn(name = "dc_activity_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_brand_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Brand> brands = new HashSet<Brand>(0);
    
    @ApiModelProperty(value = "适用品牌ID集")
    @Transient
    private Set<Integer> brandIds = new HashSet<Integer>();
    
    @ApiModelProperty(value = "适用品牌名称集")
    @Transient
    private Set<String> brandNames = new HashSet<String>();
    
    @ApiModelProperty(value = "适用门店")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_activity_shop", joinColumns = {
            @JoinColumn(name = "dc_activity_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_shop_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Shop> shops = new HashSet<Shop>(0);
    
    @ApiModelProperty(value = "适用门店ID集")
    @Transient
    private Set<Integer> shopIds = new HashSet<Integer>();
    
    @ApiModelProperty(value = "适用门店名称集")
    @Transient
    private Set<String> shopNames = new HashSet<String>();
    
    @ApiModelProperty(value = "适用项目")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_activity_item", joinColumns = {
            @JoinColumn(name = "dc_activity_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_item_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Item> items = new HashSet<Item>(0);
    
    @ApiModelProperty(value = "适用项目ID集")
    @Transient
    private Set<Integer> itemIds = new HashSet<Integer>();
    
    @ApiModelProperty(value = "适用项目名称集")
    @Transient
    private Set<String> itemNames = new HashSet<String>();

    @ApiModelProperty(value = "优惠活动所属发型师")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_hairdresser_id")
    private Hairdresser hairdresser;
    
    @ApiModelProperty(value = "优惠活动所属发型师ID")
    @Transient
    private Integer hairdresserId;

    @ApiModelProperty(value = "优惠活动所属发型师名称")
    @Transient
    private String hairdresserName;

    @ApiModelProperty(value = "生效日期")
    @Temporal(TemporalType.TIMESTAMP)
    @Column
    private Date startline;

    @ApiModelProperty(value = "截至日期")
    @Temporal(TemporalType.TIMESTAMP)
    @Column
    private Date deadline;

    @ApiModelProperty(value = "活动价格")
    @Column
    private Double price;

    @ApiModelProperty(value = "活动状态")
    @Column
    private ActivityStatus status;

    @ApiModelProperty(value = "活动发行优惠券")
    @JsonIgnore
    @OneToMany(cascade = {
            CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "activity")
    @Fetch(FetchMode.SUBSELECT)
    private Set<Coupon> coupons = new HashSet<Coupon>(0);

    @ApiModelProperty(value = "活动相关图片")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_activity_image", joinColumns = {
            @JoinColumn(name = "dc_activity_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_image_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Image> images = new HashSet<Image>(0);

    @ApiModelProperty(value = "剩余优惠券数量")
    @Transient
    private Integer remainder;

    @ApiModelProperty(value = "活动相关图片ID集")
    @Transient
    private Set<Integer> imageIds = new HashSet<Integer>(0);

    @ApiModelProperty(value = "是否已领取")
    @Transient
    private Boolean hold;

}
